<!--  -->
<template>
    <div class="page-container">
        <div class="header-panel">
            <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
                <el-form-item label="测站">
                    <StbprpSelect v-model="queryParams.stcd" placeholder="请选择测站"></StbprpSelect>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button type="primary" plain icon="el-icon-plus" @click="handleAdd"
                        v-hasPermi="['sjcx:khxxzb:add']">新增</el-button>

                    <el-button type="success" plain icon="el-icon-edit" :disabled="single" @click="handleUpdate"
                        v-hasPermi="['sjcx:khxxzb:edit']">修改</el-button>

                    <el-button type="danger" plain icon="el-icon-delete" :disabled="multiple" @click="handleDelete"
                        v-hasPermi="['sjcx:khxxzb:remove']">删除</el-button>

                </el-form-item>
            </el-form>
        </div>

        <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" size="medium"
            height="calc(100% - 100px)">
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column label="测站编码" align="center" prop="stcd" />
            <el-table-column label="开始月日" align="center" prop="bgmd" />
            <el-table-column label="结束月日" align="center" prop="edmd" />
            <el-table-column label="汛限水位" align="center" prop="fsltdz" />
            <el-table-column label="汛限库容" align="center" prop="fsltdw" />
            <el-table-column label="汛期类别" align="center" prop="fstp" :formatter="fstpformatter" />
            <el-table-column label="操作" align="center" width="160" fixed="right" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['sjcx:khxxzb:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['sjcx:khxxzb:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>


        <!-- 添加或修改用户配置对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="800px" :close-on-click-modal="false" append-to-body
            @close="dialogClose">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="测站编码" prop="stcd">
                            <StbprpSelect v-model="form.stcd" placeholder="请选择测站" :disabled="isEdit"
                                style="width: 100%;">
                            </StbprpSelect>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="开始月日" prop="bgmd">
                            <el-input v-model="form.bgmd" placeholder="请输入开始月日" :disabled="isEdit"/>
                        </el-form-item>
                    </el-col>
                </el-row>

                <!-- 第二行：结束月日、汛限水位 -->
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="结束月日" prop="edmd">
                            <el-input v-model="form.edmd" placeholder="请输入结束月日" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="汛限水位" prop="fslt dz">
                            <el-input v-model="form.fsltdz" placeholder="请输入汛限水位（单位：m）" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- 第三行：汛限库容、汛期类别 -->
                <el-row :gutter="20">
                    <el-col :span="12">
                        <el-form-item label="汛限库容" prop="fsltdw">
                            <el-input v-model="form.fsltdw" placeholder="请输入汛限库容（单位：10⁸m³）" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="汛期类别" prop="fstp">
                            <el-select v-model="form.fstp" placeholder="请选择" style="width: 100%;" clearable>
                                <el-option v-for="item in fstpOptions" :key="item.value" :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>


            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="open = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import StbprpSelect from '@/components/Select/StbprpSelect'
export default {
    components: { StbprpSelect },
    data() {
        return {
            queryParams: {},
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 勾选元素
            selection: [],
            isEdit: false,
            // 表单参数
            form: {

            },
            fstpOptions: [
                { label: '主汛期', value: '1' },
                { label: '后汛期', value: '2' },
                { label: '过渡期', value: '3' },
                { label: '其它', value: '4' },
            ],
            // 弹出层标题
            title: "",
            dataList: [],
            open: false,
            // 表单校验
            rules: {
                stcd: [
                    { required: true, message: '请选择测站编码', trigger: 'blur' },
                ],

            },
        }
    },
    computed: {},
    created() {
        this.getList();
    },
    mounted() { },
    methods: {
        getList() {
            this.loading = true;
            this.$request({
                url: '/baseApi/st_rsvrfsr_b/list',
                method: 'get',
                params: {
                    ...this.queryParams
                }
            }).then((res) => {
                if (res.code === 200) {
                    this.loading = false;
                    this.dataList = res.data;
                }
            })
        },
        handleQuery() {
            this.getList();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selection = selection
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.title = "添加信息";
            this.open = true
        },
        /** 修改按钮操作 */
        async handleUpdate(row) {
            this.form = this.selection[0] || row
            this.isEdit = true
            this.title = "修改信息";
            this.open = true
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            var ids;
            if (this.selection.length == 0) {
                ids = [row]
            } else {
                ids = this.selection
            }
            this.$confirm('是否确认删除该的数据项？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$request({
                    url: '/baseApi/st_rsvrfsr_b/delete',
                    method: 'post',
                    data: ids
                })
                    .then(res => {
                        this.handleQuery();
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                    })

            }).catch(() => { })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    let url = ''
                    if (this.isEdit) {
                        url = '/baseApi/st_rsvrfsr_b/udpate'
                    } else {
                        url = '/baseApi/st_rsvrfsr_b/insert'
                    }
                    this.$request({
                        url: url,
                        method: 'post',
                        data: this.form
                    }).then((res) => {
                        if (res.code === 200) {
                            this.open = false;
                            this.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                            this.handleQuery()
                        }
                    })
                }
            });
        },
        resetForm() {
            this.isEdit = false
            this.$data.form = this.$options.data().form
            this.$refs.form && this.$refs.form.resetFields()
        },
        dialogClose() {
            this.resetForm()
        },
        fstpformatter(row, column, cellValue, index) {
            return this.fstpOptions.find(item => item.value === cellValue)
                && this.fstpOptions.find(item => item.value === cellValue).label || '--'
        }


    },
}
</script>
<style lang="scss" scoped>
//@import url(); 引入公共css类样式</style>